const child_process = require("child_process");
const { hlog, wlog } = require("./server/utils");

function spawnChild(cmd, args = [], options = {}, callback = console.log) {
    const child = child_process.spawn(cmd, args, options);
    let stdout = "";
    let stderr = "";
    child.stdout.on("data", (data) => {
        stdout += data.toString();
        callback("stdout", stdout);
    });
    child.stderr.on("data", (data) => {
        stderr += data.toString();
        callback("stderr", stderr);
    });
    child.on("close", (code) => {
        callback("close", code);
    });
}

function main() {
    const socketChild = spawnChild("node", ["server/socket.js"], {}, wlog);
    const webChild = spawnChild("node", ["server/web.js"], {}, hlog);
}

main();
